package kbpost

import (
	// "io"
	"net/http"

	"mall/service/backend/api/internal/logic/blog/kbpost"
	"mall/service/backend/api/internal/svc"
	"mall/service/backend/api/internal/types"
	// "mall/service/backend/common/utils/excel"

	"github.com/zeromicro/go-zero/rest/httpx"
)

func DownloadAsExcelHandler(svcCtx *svc.ServiceContext) http.HandlerFunc {
	return func(w http.ResponseWriter, r *http.Request) {
		var req types.DownloadKBPostReq
		if err := httpx.Parse(r, &req); err != nil {
			httpx.ErrorCtx(r.Context(), w, err)
			return
		}

		l := kbpost.NewDownloadAsExcelLogic(r.Context(), svcCtx)
		resp, err := l.DownloadAsExcel(&req)
		if err != nil {
			httpx.ErrorCtx(r.Context(), w, err)
		} else {
			httpx.OkJsonCtx(r.Context(), w, resp)

			// reader := excel.Download("Book2.xlsx")
			// 重新设置文件名称
			// w.Header().Set("Content-Disposition", "attachment; filename="+"Book2.xlsx")
			// io.Copy(w, reader)
		}
	}
}
